﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Fly.Common.Linq;
using RN.ERP.Web.Utilities;
using System.Configuration;
using RN.ERP.Web.ModelService;
using RN.ERP.Web.PersonService;


namespace RN.ERP.Web.Handlers
{
    /// <summary>
    /// PsnEmpInfoHandler 的摘要说明
    /// </summary>
    public class PsnEmpInfoHandler : BaseHandler, IHttpHandler
    {

        public override void ProcessRequest(HttpContext context)
        {
            GetParams(context);
        }
        #region 页面数据操作
        /// <summary>
        /// 获取传递参数
        /// </summary>
        private void GetParams(HttpContext context)
        {
            Guid empGuid = Guid.NewGuid();
            string areaCode = string.Empty;
            if (!string.IsNullOrEmpty(context.Request.Params["empGuid"]))
            {
                Guid.TryParse(context.Request.Params["empGuid"], out empGuid);
            }
            //当前市场
            if (!string.IsNullOrEmpty(context.Request.Params["areaCode"]))
            {
                areaCode = context.Request.Params["areaCode"];
            }
            ////异步调用方法
            if (context.Request.Params["action"] != null)
            {
                string action = context.Request.Params["action"];
                switch (action)
                {
                    case "Qualitie":
                        GetEmpQualities(empGuid.ToString(), areaCode, context);
                        break;
                    case "QualitieSC":
                        GetEmpQualitiesSC(empGuid.ToString(), areaCode, context);
                        break;
                    case "Experience":
                        GetWorkExperience(empGuid.ToString(), areaCode);
                        break;
                    case "UserLog":
                        GetUserLog(empGuid.ToString(), areaCode, context);
                        break;
                    case "QualitieDel":
                        EmpQualityMultiDel(empGuid.ToString(), areaCode, context);
                        break;
                    case "ExperienceDel":
                        WorkExperienceDel(empGuid.ToString(), areaCode, context);
                        break;
                    case "EmpInfoAdd":
                        EmpInfoSave(true, empGuid, areaCode, context);
                        break;
                    case "EmpInfo":
                        GetEmpManagersList(empGuid.ToString(), areaCode);
                        break;
                    case "EmpInfoEdit":
                        EmpInfoSave(false, empGuid, areaCode, context);
                        break;
                    case "CardCheck":
                        EmpCardCheck(empGuid.ToString(), areaCode, context);
                        break;
                    case "PostPszg":
                        Initial(areaCode);
                        break;
                    case "EmpPost":
                        EmpInfoPost(context.Request.QueryString["empGuid"], areaCode, context);
                        break;
                    case "EmpCertPost":
                        EmpCertPost(context.Request.QueryString["eduGuid"], areaCode, context);
                        break;
                    case "AddTypeFlag":
                        EmpInfoAddTypeFlag(empGuid.ToString(), areaCode, context);
                        break;
                    case "EmpInfoAudit":
                        EmpInfoAudit(context.Request.QueryString["empGuid"], areaCode, context);
                        break;
                    case "empDels":
                        Empdel(context.Request.QueryString["empGuid"], areaCode);
                        break;
                    case "empImport":
                        EmpImport(context.Request.QueryString["empGuid"], areaCode, context);
                        break;
                    case "EmpIsExist":
                        CheckEmpIsExist(empGuid.ToString(), areaCode);
                        break;
                    case "Expert":
                        GetExpertSpecialityList(empGuid.ToString(), areaCode, context);
                        break;
                    case "SpecDel":
                        ExpertSpecialityDel(empGuid.ToString(), areaCode, context);
                        break;
                    case "Relation":
                        GetExpertRelationList(empGuid.ToString(), areaCode, context);
                        break;
                    case "RelationSave":
                        ExpertRelationSave(empGuid.ToString(), areaCode, context);
                        break;
                    case "RelationDel":
                        ExpertRelationDelete(empGuid.ToString(), areaCode, context);
                        break;
                    case "Tree":
                        GetTreeDeptData(context);
                        break;
                    case "LoadSpecDics":
                        LoadSpecDics(context);
                        break;
                    case "IsZZemp":
                        SetPersonIsZZemp(context.Request.QueryString["empGuid"], areaCode, context);
                        break;
                    case "ImportEmpCert":
                        ImportEmpTitleDetails(context.Request.Params["idCard"], empGuid.ToString(), areaCode);
                        break;
                    case "ExportPdf":
                        ExportPdf(empGuid.ToString(), areaCode, context);
                        break;
                    case "DelRelationCorp":
                        DeleteUserRelationCorp(empGuid.ToString(), areaCode, context);
                        break;
                    case "ExpertPost":
                        ExpertPost(empGuid.ToString(), areaCode, context);
                        break;
                    case "EmpPostPost":
                        EmpPostPost(areaCode, context);
                        break;
                    case "GetEmpPost":
                        GetEmpPostByEmpGuid(areaCode, context);
                        break;
                    case "EmpPostInfoPost":
                        EmpPostInfoPost(context.Request.QueryString["empGuid"], areaCode, context);
                        break;
                    case "getnonpostexp":
                        GetNonPostExperts(context.Request.QueryString["areaCode"], context.Request.QueryString["type"], context);
                        break;
                }
            }
        }

        /// <summary>
        /// 输出JSON格式数据到页面
        /// </summary>
        /// <param name="dataStr"></param>
        private void OutputData(string dataStr)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(dataStr);
            // HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }

        #region 人员基本信息
        /// <summary>
        /// 取得人员基本信息，职称，安全考核证
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="AreaCode"></param>
        private void GetEmpManagersList(string empGuid, string areaCode)
        {
            Guid empGuid1 = Guid.Empty;
            Guid.TryParse(empGuid, out empGuid1);
            if (empGuid1 == Guid.Empty)
            {
                var result1 = "{\"result\":1,\"message\":\"参数错误！\"}";
                OutputData(result1);
                return;
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {

                ModelService.QueryPersonInfoCondition queryCondition = new ModelService.QueryPersonInfoCondition()
                {
                    EmpGuid = new ParameterValue<Guid> { V = empGuid1, O = OptEnum.Equal }
                };
                List<ModelService.QueryPersonInfoCondition> query = new List<ModelService.QueryPersonInfoCondition>() { queryCondition };
                string queryStr = JsonConvert.SerializeObject(query);
                var manages = client.GetEmpManagersAllList(1, 0, queryStr, areaCode);
                if(AppID=="95")
                {
                    IList<ModelService.tb_Emp_Manager> model = JsonConvert.DeserializeObject<IList<ModelService.tb_Emp_Manager>>(manages);
                    if (model != null)
                    {
                        BasicService.BasicServiceClient baseService = new BasicService.BasicServiceClient();
                        foreach (var item in model)
                        {
                            item.EmployeeType = baseService.GetExpertDBName(item.DBType);
                        }
                    }
                    manages = JsonConvert.SerializeObject(model);
                }
                var result = "{\"result\":0,\"empInfo\":" + manages + ",\"empPost\":" + GetEmpEmpPosts(empGuid, areaCode) + ",\"empExt\":" + GetEmpTitleDetailsExt(empGuid, areaCode) + "}";
                OutputData(result);
            }
        }

        /// <summary>
        /// 根据图片编号和文件标识，返回未上传的图片信息
        /// </summary>
        /// <param name="funcCodes">图片编号拼成的字符串</param>
        /// <param name="fileNames">文件标识拼成的字符串</param>
        private string CheckRequiredImgs(string funcCodes, string fileNames)
        {
            string[] funcCodeArr = funcCodes.Split(',');
            string[] fileNameArr = fileNames.Split(',');
            string result = String.Empty;
            funcCodes = String.Empty;
            fileNames = String.Empty;

            for (int i = 0; i < funcCodeArr.Length; i++)
            {
                string func = funcCodeArr[i];

                ////如果包含头像，则SysCode要单独处理(因为没有水印，用的独立的一个SysCode)
                if (func == "Person")
                {
                    result = UtilitiesTool.IsImgFileExists(fileNameArr[i], "EFNoWater", "Person");
                    if (!string.IsNullOrEmpty(result))
                    {
                        return result;
                    }
                }
                else
                {
                    funcCodes += "," + func;
                    fileNames += "," + fileNameArr[i];
                }
            }
            funcCodes = funcCodes.TrimStart(',');
            fileNames = fileNames.TrimStart(',');

            result = UtilitiesTool.IsImgFileExists(fileNames, "EF", funcCodes);
            if (!string.IsNullOrEmpty(result))
            {
                return result;
            }
            return result;
        }

        /// <summary>
        /// 添加修改人员基本信息
        /// </summary>
        private void EmpInfoSave(bool flag, Guid empGuid, string areaCode, HttpContext context)
        {
            if (context.Request.Params["data"] == null)
            {
                OutputData("{\"Result\":false,\"Message\":\"数据错误！\"}");
                return;
            }
            ///判断必传图片是否上传
            if (context.Request.Params["funcCode"] != null && context.Request.Params["filename"] != null)
            {
                string funcCodes = context.Request.Params["funcCode"].TrimEnd(',');
                string fileNames = context.Request.Params["filename"].TrimEnd(',');
                string result = CheckRequiredImgs(funcCodes, fileNames);

                if (!string.IsNullOrEmpty(result))
                {
                    OutputData("{\"Result\":false,\"Message\":\"img\",\"ReturnValue\":\"" + result + "\"}");
                    return;
                }
            }
            //取得提交数据
            string data = context.Request.Params["data"];//取得客户端提交的数据

            //转化数据为key-value对象列表
            var managers = JsonConvert.DeserializeObject<List<JsonEntity>>(context.Request.Params["data"]);
            ModelService.tb_Emp_Manager empInfo = null;
            List<ModelService.Tb_Emp_Post> empPost = null;
            List<ModelService.Tb_Emp_TitleDetailsExt> empTDExt = null;
            foreach (var manager in managers)
            {
                var valStr = manager.value.Trim('\"');//对象值为json格式的对象实体
                //根据key值转化实体对象
                switch (manager.key)
                {
                    case "tb_emp_manager":
                        empInfo = JsonConvert.DeserializeObject<ModelService.tb_Emp_Manager>(valStr);
                        break;
                    case "tb_emp_post":
                        empPost = JsonConvert.DeserializeObject<List<ModelService.Tb_Emp_Post>>(valStr);
                        break;
                    case "tb_emp_titledetailsext":
                        empTDExt = JsonConvert.DeserializeObject<List<ModelService.Tb_Emp_TitleDetailsExt>>(valStr);
                        break;
                }
            }
            if (empInfo != null)
            {
                using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
                {
                    string result = "";
                    string corpGuid = string.Empty;
                    if (context.Request.Params["corpGuid"] != null)
                    {
                        corpGuid = context.Request.Params["corpGuid"].ToString();
                    }
                    empInfo.EmpGuid = empGuid;
                    //执行添加或修改事件
                    if (flag)
                    {
                        result = client.EmpPersonInfoAdd(corpGuid, JsonConvert.SerializeObject(empInfo), JsonConvert.SerializeObject(empTDExt), JsonConvert.SerializeObject(empPost), true, areaCode);
                    }
                    else
                    {
                        //empInfo.EmpGuid = empGuid;
                        result = client.EmpPersonInfoEdit(corpGuid, JsonConvert.SerializeObject(empInfo), JsonConvert.SerializeObject(empTDExt), JsonConvert.SerializeObject(empPost), areaCode);
                    }
                    OutputData(result);
                }
            }
        }

        /// <summary>
        /// 身份证验证
        /// </summary>
        /// <param name="empGuid"></param>
        private void CheckEmpIsExist(string empGuid, string areaCode)
        {
            if (string.IsNullOrEmpty(empGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息不存在！\"}";
                OutputData(result);
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.CheckEmpIsExist(empGuid, areaCode));
            }
        }
        /// <summary>
        /// 身份证验证
        /// </summary>
        /// <param name="empGuid"></param>
        private void EmpCardCheck(string empGuid, string areaCode, HttpContext context)
        {
            string IDCard = string.Empty;//身份证
            string corpUserGuid = string.Empty;
            if (context.Request.Params["IDCard"] != null)
            {
                IDCard = context.Request.Params["IDCard"].ToString();
            }
            if (context.Request.Params["corpGuid"] != null)
            {
                corpUserGuid = context.Request.Params["corpGuid"].ToString();
            }
            if (string.IsNullOrEmpty(IDCard) || string.IsNullOrEmpty(empGuid) || string.IsNullOrEmpty(corpUserGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"身份证或人员信息为空！\"}";
                OutputData(result);
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.IDCardIsExists(IDCard, corpUserGuid, empGuid, areaCode));
            }
        }

        /// <summary>
        /// 人员职称信息
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="AreaCode"></param>
        public string GetEmpEmpPosts(string empGuid, string areaCode)
        {
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                return client.GetEmpEmpPosts(empGuid, areaCode);
            }
        }

        /// <summary>
        /// 页面初始化-返回所有二级职称
        /// </summary>
        /// <param name="EmpGuid"></param>
        /// <param name="AreaCode"></param>
        private void Initial(string areaCode)
        {
            using (BasicService.BasicServiceClient client = new BasicService.BasicServiceClient())
            {
                var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(client.GetDictionary("post", "", areaCode));
                OutputData(JsonConvert.SerializeObject(result));
            }
        }

        /// <summary>
        /// 人员安全考核证
        /// </summary>
        public string GetEmpTitleDetailsExt(string empGuid, string areaCode)
        {
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                return client.GetEmpTitleDetailsExt(empGuid, areaCode);
            }
        }

        /// <summary>
        /// 判断当前专家是否有权审核
        /// </summary>
        private bool IsCheckRoleValid(string empGuid)
        {
            List<QueryPersonInfoCondition> queryList = new List<QueryPersonInfoCondition>();
            QueryPersonInfoCondition condition = new QueryPersonInfoCondition();
            PersonServiceClient personClient = new PersonServiceClient();
            Guid guid = Guid.Empty;
            if (!Guid.TryParse(empGuid, out guid))
            {
                return false;
            }
            condition.EmpGuid = new ParameterValue<Guid>() { O = OptEnum.Equal, V = guid };
            queryList.Add(condition);
            int count = 0;
            var experts = personClient.GetExpertsList(1, 1, JsonConvert.SerializeObject(queryList), "00", out count);
            var expert = JsonConvert.DeserializeObject<IList<tb_Emp_Manager>>(experts).FirstOrDefault();

            if (expert != null)
            {
                ////判断是否是使用专家系统的市级主管
                if (UserInfo.LocalArea != "01" && UserInfo.RoleId != null && UserInfo.RoleId == "87")
                {
                    if (expert.AreaCode.EndsWith("01"))
                    {
                        return true;
                    }
                    ////如果不是市直，则不可以审核上报和再上报的
                    return expert.FlowCode != "0,019" && expert.FlowCode != "0,019,022";
                }
            }
            return true;
        }

        /// <summary>
        /// 人员上报
        /// </summary>
        /// <param name="empGuid"></param>
        private void EmpInfoPost(string empGuid, string areaCode, HttpContext context)
        {
            string corpUserGuid = string.Empty;
            string description = string.Empty;
            string message = string.Empty;
            string appId = ConfigurationManager.AppSettings["AppId"] ?? "";
            int optType = 4;
            if (context.Request.Params["corpGuid"] != null)
            {
                corpUserGuid = context.Request.Params["corpGuid"].ToString();
            }
            if (appId == "95")
            {
                if (!IsCheckRoleValid(empGuid))
                {
                    string result = "{\"Result\":false,\"Message\":\"操作失败，请检查专家的审核状态。\"}";
                    OutputData(result);
                }
            }
            if (string.IsNullOrEmpty(empGuid) || string.IsNullOrEmpty(corpUserGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            if (context.Request.Params["optType"] != null)
            {
                int.TryParse(context.Request.Params["optType"], out optType);
            }
            //必传图片判断,上报验证
            if (optType == 4)
            {
                string result1 = CheckPsnUpLoadFile(empGuid, areaCode);
                if (!string.IsNullOrEmpty(result1))
                {
                    OutputData(result1);
                }
            }
            if (context.Request.Params["message"] != null)
            {
                message = context.Request.Params["message"].ToString();
            }
            if (context.Request.Params["descr"] != null)
            {
                description = context.Request.Params["descr"].ToString();
            }
            //服务参数不够，用User_Log对象传递参数
            ModelService.User_Log log = new ModelService.User_Log();
            if (optType == 51)
            {
                log.IsrtUserArea = "true";////用于专家系统中【有条件通过】
                optType = 5;
            }
            log.FunctionId = optType.ToString();
            log.FunctionType = message;
            log.Notice = description;
            ////上报
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                string[] arry = empGuid.Split(',');
                if (appId == "95")
                {
                    OutputData(client.ExpertInfoPost(corpUserGuid, JsonConvert.SerializeObject(arry), JsonConvert.SerializeObject(log), areaCode));
                }
                OutputData(client.EmpInfoPost(corpUserGuid, JsonConvert.SerializeObject(arry), JsonConvert.SerializeObject(log), areaCode));
            }
        }
        /// <summary>
        /// 判断人员相关图片是否上传
        /// </summary>
        private string CheckPsnUpLoadFile(string empGuid, string areaCode)
        {
            string appId = ConfigurationManager.AppSettings["AppId"] ?? "";
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                string[] arry = empGuid.Split(',');
                List<ModelService.PsnFileNames> list = JsonConvert.DeserializeObject<List<ModelService.PsnFileNames>>(client.GetPsnFileNames(JsonConvert.SerializeObject(arry), appId, areaCode));
                if (list == null || list.Count == 0)
                {
                    return null;
                }
                string result = string.Empty;
                ///判断必传图片是否上传
                foreach (var img in list)
                {
                    string funcCodes = img.FileType;
                    string filenames = img.FileNames;
                    result = UtilitiesTool.IsFileExists(filenames, "EF", funcCodes);
                    if (!string.IsNullOrEmpty(result))
                    {
                        result = "{\"Result\":false,\"Message\":\"img\",\"ReturnValue\":\"人员[" + img.EmpName + "]的" + img.Title + "未上传扫描件，不能执行此操作！\"}";
                        break;
                    }
                }
                return result;
            }
        }
        /// <summary>
        /// 通过身份证导入人员
        /// </summary>
        /// <param name="empGuid"></param>
        private void EmpInfoAddTypeFlag(string empGuid, string areaCode, HttpContext context)
        {
            string typeFlag = string.Empty;
            string corpUserGuid = string.Empty;
            if (context.Request.Params["typeFlag"] != null)
            {
                typeFlag = context.Request.Params["typeFlag"].ToString();
            }
            if (string.IsNullOrEmpty(typeFlag) || string.IsNullOrEmpty(empGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.EmpInfoAddTypeFlag(empGuid, typeFlag, areaCode));
            }
        }

        /// <summary>
        /// 人员审核、退回
        /// </summary>
        /// <param name="empGuid"></param>
        private void EmpInfoAudit(string empGuid, string areaCode, HttpContext context)
        {
            string corpUserGuid = string.Empty;
            string description = string.Empty;
            int optType = 5;
            if (context.Request.Params["corpGuid"] != null)
            {
                corpUserGuid = context.Request.Params["corpGuid"].ToString();
            }
            if (context.Request.Params["descr"] != null)
            {
                description = context.Request.Params["descr"].ToString();
            }
            if (context.Request.Params["optType"] != null)
            {
                int.TryParse(context.Request.Params["optType"], out optType);
            }
            if (string.IsNullOrEmpty(empGuid) || string.IsNullOrEmpty(corpUserGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            ////审核
            string[] arry = empGuid.Split(',');
            //审核服务参数不够，用User_Log对象传递参数
            ModelService.User_Log log = new ModelService.User_Log();
            log.IsrtUser = corpUserGuid;
            log.FunctionId = optType.ToString();
            log.FunctionType = "";
            log.Notice = description;
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.EmpInfoAudit(JsonConvert.SerializeObject(arry), false, areaCode, JsonConvert.SerializeObject(log), string.Empty, description, false, false));
            }
        }

        /// <summary>
        /// 删除人员
        /// </summary>
        private void Empdel(string empGuid, string areaCode)
        {
            if (string.IsNullOrEmpty(empGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            string[] emps = empGuid.Split(',');
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.EmpInfoDel(emps, areaCode));
            }
        }
        /// <summary>
        /// 批量导入人员
        /// </summary>
        private void EmpImport(string empGuid, string areaCode, HttpContext context)
        {
            if (string.IsNullOrEmpty(empGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            string corpUserGuid = string.Empty;
            if (context.Request.Params["corpGuid"] != null)
            {
                corpUserGuid = context.Request.Params["corpGuid"].ToString();
            }
            string[] emps = empGuid.Split(',');
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.EmpInfoImport(corpUserGuid, emps, areaCode));
            }
        }
        #endregion

        #region 证书,工作经历,日志
        /// <summary>
        /// 人员资格证书查询
        /// </summary>
        private void GetEmpQualities(string empGuid, string areaCode, HttpContext context)
        {
            string type = "ZGZS";////默认显示资格证书
            int isValid = -1;////是否导入            
            if (context.Request.QueryString["type"] != null)
            {
                type = context.Request.QueryString["type"].Trim();
            }
            if (context.Request.QueryString["isValid"] != null)
            {
                int.TryParse(context.Request.QueryString["isValid"].Trim(), out isValid);
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var list = JsonConvert.DeserializeObject<List<ModelService.Tb_Emp_TitleDetails>>(client.GetEmpQualities(empGuid, areaCode));
                list = list.Where(q => q.StampCode == type).ToList();
                if (isValid >= 0)
                {
                    list = list.Where(q => q.IsValid == isValid).ToList();
                }
                OutputData(JsonConvert.SerializeObject(list));
            }
        }
        /// <summary>
        /// 人员资格证书删除
        /// </summary>
        private void EmpQualityMultiDel(string empGuid, string areaCode, HttpContext context)
        {
            string educationGUID = string.Empty;
            if (!string.IsNullOrEmpty(context.Request.Params["keyId"]))
            {
                educationGUID = context.Request.Params["keyId"];
                using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
                {
                    OutputData(client.EmpQualityMultiDel(educationGUID, empGuid, areaCode));
                }
            }

        }
        /// <summary>
        /// 人员主要工作经历查询
        /// </summary>
        private void GetWorkExperience(string empGuid, string areaCode)
        {
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.GetWorkExperienceList(empGuid, areaCode));
            }
        }

        /// <summary>
        /// 人员主要工作经历删除
        /// </summary>
        /// <param name="empGuid"></param>
        private void WorkExperienceDel(string empGuid, string areaCode, HttpContext context)
        {
            string workExpId = string.Empty;
            if (!string.IsNullOrEmpty(context.Request.Params["keyId"]))
            {
                workExpId = context.Request.Params["keyId"];
                using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
                {
                    OutputData(client.WorkExperienceDel(workExpId, empGuid, areaCode));
                }
            }
        }

        /// <summary>
        /// 查询操作日志
        /// </summary>
        private void GetUserLog(string empGuid, string areaCode, HttpContext context)
        {
            int starNum = 1;//当前页
            int pageSize = 5;//每页数
            string userRole = "User";
            if (context.Request.Params["pageNo"] != null)
            {
                int.TryParse(context.Request.Params["pageNo"].ToString(), out starNum);
            }
            if (context.Request.Params["pageSize"] != null)
            {
                int.TryParse(context.Request.Params["pageSize"].ToString(), out pageSize);
            }
            if (context.Request.Params["userRole"] != null)
            {
                userRole = context.Request.Params["userRole"];
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                int allCount = client.GetUserLogCount(empGuid, userRole, areaCode);
                string allList = client.GetUserLogList(starNum, pageSize, empGuid, userRole, areaCode);
                string result = "{\"pageCount\":" + allCount + ",\"data\":" + allList + "}";
                OutputData(result);

            }
        }

        #endregion

        /// <summary>
        /// 锁定人员
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="areaCode"></param>
        /// <param name="context"></param>
        private void SetPersonIsZZemp(string empGuid, string areaCode, HttpContext context)
        {
            byte empFlag = 0;
            byte.TryParse(context.Request.Params["empFlag"], out empFlag);
            if (string.IsNullOrEmpty(empGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            string[] emps = empGuid.Split(',');
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.SetPersonIsZZemp(emps, empFlag, areaCode));
            }
        }

        /// <summary>
        /// 取得人员执业手册列表
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="areaCode"></param>
        /// <param name="context"></param>
        private void GetEmpQualitiesSC(string empGuid, string areaCode, HttpContext context)
        {
            string type = "ZGZS";
            int codeType = 251201;//执业手册审核状态标识
            if (context.Request.QueryString["type"] != null)
            {
                type = context.Request.QueryString["type"].Trim();
            }
            if (context.Request.QueryString["codeType"] != null)
            {
                int.TryParse(context.Request.QueryString["codeType"].Trim(), out codeType);
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var list = JsonConvert.DeserializeObject<List<ModelService.Tb_Emp_TitleDetails>>(client.GetEmpTitleDetails(empGuid, codeType, areaCode));
                OutputData(JsonConvert.SerializeObject(list.Where(q => q.StampCode == type).ToList()));
            }
        }

        #region 评标专家操作

        /// <summary>
        /// 从注册中心取用户的执业注册信息导入数据库
        /// </summary>
        /// <param name="idCard"></param>
        /// <param name="empGuid"></param>
        /// <param name="areaCode"></param>
        private void ImportEmpTitleDetails(string idCard, string empGuid, string areaCode)
        {
            if (string.IsNullOrEmpty(idCard) || idCard.Length < 15)
            {
                OutputData("{\"Result\":false,\"message\":\"参数错误！\"}");
                return;
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OutputData(client.ImportEmpTitleDetails(idCard, empGuid, areaCode));
            }
        }

        /// <summary>
        /// 取得专家导出pdf替换数据
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="areaCode"></param>
        /// <param name="context"></param>
        private void ExportPdf(string empGuid, string areaCode, HttpContext context)
        {
            string sysCodes = string.Empty;
            string funcCodes = string.Empty;
            string corpGuid = string.Empty;
            string empName = string.Empty;
            if (!string.IsNullOrEmpty(context.Request.QueryString["sysCode"]))
            {
                sysCodes = context.Request.QueryString["sysCode"].Trim();
            }
            if (!string.IsNullOrEmpty(context.Request.QueryString["funcCode"]))
            {
                funcCodes = context.Request.QueryString["funcCode"].Trim();
            }
            if (context.Request.Params["corpGuid"] != null)
            {
                corpGuid = context.Request.Params["corpGuid"].ToString();
            }
            if (context.Request.Params["empName"] != null)
            {
                empName = context.Request.Params["empName"].ToString();
            }
            ////组合替换数据
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("$EmpName", empName);
            dict.Add("$CompanyName", GetCompanyName(corpGuid, areaCode));
            //取得上传文件参数
            if (!string.IsNullOrEmpty(sysCodes) && !string.IsNullOrEmpty(funcCodes))
            {
                string ImgBrowseUrl = string.Empty;
                if (System.Configuration.ConfigurationManager.AppSettings["ImgBrowseUrl"] != null)
                {
                    ImgBrowseUrl = System.Configuration.ConfigurationManager.AppSettings["ImgBrowseUrl"].ToString();
                }
                string[] sCodes = sysCodes.TrimEnd(',').Split(',');
                string[] fCodes = funcCodes.TrimEnd(',').Split(',');
                string url = string.Empty;
                string showStatus = "none";
                FileService.FileWebServiceSoapClient fileService = new FileService.FileWebServiceSoapClient();
                {
                    for (int i = 0; i < sCodes.Length; i++)
                    {
                        if (string.IsNullOrEmpty(sCodes[i]) || string.IsNullOrEmpty(fCodes[i]))
                        {
                            continue;
                        }
                        ///判断是否有上传扫描件
                        if (fileService.GetFileList(empGuid, sCodes[i], fCodes[i]).Count == 0)
                        {
                            url = "#";
                            showStatus = "none";
                        }
                        else
                        {
                            url = ImgBrowseUrl + "?fileName=" + empGuid + ".jpg&sysCode=EF&funcCode=" + fCodes[i] + "&rand=" + Guid.NewGuid().ToString();
                            showStatus = "block";
                        }
                        dict.Add("$" + fCodes[i], url);
                        dict.Add("$01" + fCodes[i], showStatus);
                    }
                }
                /////资格证书
                if (fCodes.Contains("PersonZG"))
                {
                    string zsGuid = GetEmpQualitiesGuid(empGuid, areaCode, context);
                    if (!string.IsNullOrEmpty(zsGuid) && dict.ContainsKey("$PersonZG") && dict.ContainsKey("$01PersonZG"))
                    {
                        dict["$PersonZG"] = ImgBrowseUrl + "?fileName=" + zsGuid + ".jpg&sysCode=EF&funcCode=PersonZG&rand=" + Guid.NewGuid().ToString();
                        dict["$01PersonZG"] = "block";
                    }
                }
            }
            OutputData("{\"parameters\":\"" + HttpContext.Current.Server.UrlEncode(JsonConvert.SerializeObject(dict)) + "\"}");

        }

        /// <summary>
        /// 返回有证书图片的证书Guid
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="areaCode"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetEmpQualitiesGuid(string empGuid, string areaCode, HttpContext context)
        {
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var zslist = JsonConvert.DeserializeObject<List<ModelService.Tb_Emp_TitleDetails>>(client.GetEmpQualities(empGuid, areaCode));
                if (zslist != null && zslist.Count > 0)
                {
                    var guids = zslist.Where(q => q.StampCode == "ZGZS").Select(z => z.EducationGUID).ToList();
                    FileService.FileWebServiceSoapClient fileService = new FileService.FileWebServiceSoapClient();
                    {
                        for (int i = 0; i < guids.Count; i++)
                        {
                            ///判断是否有上传扫描件
                            if (fileService.GetFileList(guids[i].ToString(), "EF", "PersonZG").Count > 0)
                            {
                                return guids[i].ToString();
                            }
                        }
                    }
                }
                return string.Empty;
            }
        }

        /// <summary>
        /// 返回专家单位名称
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        private string GetCompanyName(string corpUserGuid, string areaCode)
        {
            try
            {
                ////获取单位信息
                using (EnterpriseService.EnterpriseServiceClient enterpriseServiceClient = new EnterpriseService.EnterpriseServiceClient())
                {
                    List<ModelService.QueryCompanyInfoCondition> queryCompanyInfoList = new List<ModelService.QueryCompanyInfoCondition>() 
                   {
                      new ModelService.QueryCompanyInfoCondition() { CorpUserGuid = new ParameterValue<Guid>() { V = Guid.Parse(corpUserGuid), O = OptEnum.Equal } }
                   };
                    var jcorp = enterpriseServiceClient.GetCompanyInfo(JsonConvert.SerializeObject(queryCompanyInfoList), areaCode);
                    var corpInfo = JsonConvert.DeserializeObject<ModelService.Tb_Corp_CompanyInfo>(jcorp);

                    return corpInfo.CorpName;
                }
            }
            catch { }
            return string.Empty;

        }


        /// <summary>
        /// 删除专家关系单位
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="entityName"></param>
        /// <param name="areaCode"></param>
        private void DeleteUserRelationCorp(string empGuid, string areaCode, HttpContext context)
        {
            try
            {
                string corpNames = string.Empty;
                if (context.Request.Params["entityName"] != null)
                {
                    corpNames = context.Request.Params["entityName"].Trim();
                }
                using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
                {
                    foreach (string corpName in corpNames.Split(','))
                    {
                        if (corpName.Trim().Length > 0)
                        {
                            client.DeleteUserRelationCorp(empGuid, 1002, corpName.Trim(), areaCode);
                        }
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// 专家上报
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="areaCode"></param>
        /// <param name="context"></param>
        private void ExpertPost(string empGuid, string areaCode, HttpContext context)
        {
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                ////验证工作经历是否添加
                ModelService.OperationResult r = JsonConvert.DeserializeObject<ModelService.OperationResult>(client.CheckWorkExperience(empGuid, areaCode));
                if (!r.Result)
                {
                    OutputData("{\"Result\":false,\"Message\":\"" + r.Message + "\"}");
                    return;
                }
                //var works = JsonConvert.DeserializeObject<List<ModelService.tb_WorkExperience>>(client.GetWorkExperienceList(empGuid, areaCode));
                //if (works == null || works.Count() == 0)
                //{
                //    OutputData("{\"Result\":false,\"Message\":\"请先添加工作经历，再上报！\"}");
                //    return;
                //}
                ////验证主专业是否添加
                var result = JsonConvert.DeserializeObject<ModelService.OperationResult>(client.ExpertMainSpecCheck(empGuid, areaCode));
                if (!result.Result)
                {
                    OutputData(JsonConvert.SerializeObject(result));
                    return;
                }
            }
            EmpInfoPost(empGuid, areaCode, context);

        }

        #endregion

        #region 专家管理
        private void GetExpertSpecialityList(string empGuid, string areaCode, HttpContext context)
        {
            string isMain = string.Empty;
            if (context.Request.QueryString["isMain"] != null)
            {
                isMain = context.Request.QueryString["isMain"].Trim();
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var list = JsonConvert.DeserializeObject<List<ModelService.tb_Expert_Speciality>>(client.GetExpertSpecialityList(empGuid, areaCode));
                if (isMain.ToUpper() == "TRUE" && list != null)
                {
                    list = list.Where(o => o.IsMain != null && o.IsMain == true).ToList();
                    OutputData(JsonConvert.SerializeObject(list));
                }
                else if (isMain.ToUpper() == "FALSE" && list != null)
                {
                    list = list.Where(o => o.IsMain != null && o.IsMain == false).ToList();
                    OutputData(JsonConvert.SerializeObject(list));
                }
            }
        }

        private void ExpertSpecialityDel(string empGuid, string areaCode, HttpContext context)
        {
            string guid = string.Empty;
            if (context.Request.QueryString["Guid"] != null)
            {
                guid = context.Request.QueryString["Guid"].Trim();
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var result = client.DeleteSpeciality(guid, areaCode);
                OutputData(result);
            }
        }

        private void GetExpertRelationList(string empGuid, string areaCode, HttpContext context)
        {
            int flag = -1;
            if (context.Request.QueryString["flag"] != null)
            {
                string type = context.Request.QueryString["flag"];
                if (!string.IsNullOrEmpty(type))
                {
                    int.TryParse(type, out flag);
                }
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var list = JsonConvert.DeserializeObject<List<ModelService.tb_User_Relation>>(client.GetUserRelationList(empGuid, flag, areaCode));
                if (flag == 0)
                {
                    if (UserInfo.RoleType == "Manager")
                    {
                    }
                    else
                    {
                        list = list.Where(o => o.AreaCode == string.Empty).ToList();
                    }
                }
                OutputData(JsonConvert.SerializeObject(list));
            }
        }

        private void ExpertRelationSave(string empGuid, string areaCode, HttpContext context)
        {
            int flag = -1;
            string entityGuid = string.Empty;
            string entityName = string.Empty;
            string reason = string.Empty;
            string gid = string.Empty;
            int classId = 1000;
            if (context.Request.QueryString["flag"] != null)
            {
                string type = context.Request.QueryString["flag"];
                if (!string.IsNullOrEmpty(type))
                {
                    int.TryParse(type, out flag);
                }
            }
            if (context.Request.QueryString["ClassId"] != null)
            {
                string type = context.Request.QueryString["ClassId"];
                if (!string.IsNullOrEmpty(type))
                {
                    int.TryParse(type, out classId);
                }
            }
            if (context.Request.QueryString["EntityGuid"] != null)
            {
                entityGuid = context.Request.QueryString["EntityGuid"].Trim();
            }
            if (classId == 1001)
            {
                entityGuid = Guid.NewGuid().ToString();
            }
            if (flag == 0)
            {
                if (context.Request.QueryString["Reason"] != null)
                {
                    reason = context.Request.QueryString["Reason"].Trim();
                }
            }
            if (context.Request.QueryString["EntityName"] != null)
            {
                entityName = context.Request.QueryString["EntityName"].Trim();
            }
            if (context.Request.QueryString["Gid"] != null)
            {
                gid = context.Request.QueryString["Gid"].Trim();
            }
            if (string.IsNullOrEmpty(entityGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"参数无效！\"}";
                OutputData(result);
            }
            ModelService.tb_User_Relation model = new ModelService.tb_User_Relation();
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                if (string.IsNullOrEmpty(gid))
                {
                    model.Gid = Guid.NewGuid();
                    model.ID = 0;
                    model.UserGuid = Guid.Parse(empGuid);
                    model.CreateTime = DateTime.Now;
                    model.EntityFlag = byte.Parse(flag.ToString());
                    model.EntityGuid = Guid.Parse(entityGuid);
                    model.EntityName = entityName;
                    model.AreaCode = areaCode;
                    model.ClassId = classId;
                    if (flag == 0)////回避专家
                    {
                        model.Reason = reason;
                        if (!String.IsNullOrEmpty(UserInfo.RoleType))
                        {
                            if (UserInfo.RoleType == "Manager")
                            {
                                model.AreaCode = UserInfo.LocalArea;
                            }
                        }
                    }
                    else
                    {
                        model.Reason = "申请人自主添加";
                    }
                    model.AppId = 95;
                    var result = client.SaveUserRelationInfo(JsonConvert.SerializeObject(model), areaCode);
                    OutputData(result);
                }
                else
                {
                    model = JsonConvert.DeserializeObject<ModelService.tb_User_Relation>(client.GetUserRelationInfo(gid, areaCode));
                    model.EntityGuid = Guid.Parse(entityGuid);
                    model.EntityName = entityName;
                    model.ClassId = classId;
                    if (!String.IsNullOrEmpty(UserInfo.RoleType))
                    {
                        if (UserInfo.RoleType == "Manager")
                        {
                            model.AreaCode = UserInfo.LocalArea;
                        }
                    }
                    if (!String.IsNullOrEmpty(reason))
                    {
                        model.Reason = reason;
                    }
                    var result = client.SaveUserRelationInfo(JsonConvert.SerializeObject(model), areaCode);
                    OutputData(result);
                }
            }
        }

        private void ExpertRelationDelete(string empGuid, string areaCode, HttpContext context)
        {
            string gid = string.Empty;
            if (context.Request.QueryString["Gid"] != null)
            {
                gid = context.Request.QueryString["Gid"].Trim();
            }
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var result = client.DeleteUserRelation(gid, areaCode);
                OutputData(result);
            }
        }

        /// <summary>
        /// 人员证书上报审核
        /// </summary>
        /// <param name="empGuid"></param>
        private void EmpCertPost(string eduGuid, string areaCode, HttpContext context)
        {
            string corpUserGuid = string.Empty;
            string description = string.Empty;
            string message = string.Empty;
            string appId = ConfigurationManager.AppSettings["AppId"] ?? "";
            int optType = 4;
            if (context.Request.Params["corpGuid"] != null)
            {
                corpUserGuid = context.Request.Params["corpGuid"].ToString();
            }
            if (string.IsNullOrEmpty(eduGuid) || string.IsNullOrEmpty(corpUserGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            if (context.Request.Params["optType"] != null)
            {
                int.TryParse(context.Request.Params["optType"], out optType);
            }
            //必传图片判断,上报验证
            //if (optType == 4)
            //{
            //    string result1 = CheckPsnUpLoadFile(empGuid, areaCode);
            //    if (!string.IsNullOrEmpty(result1))
            //    {
            //        OutputData(result1);
            //    }
            //}
            if (context.Request.Params["message"] != null)
            {
                message = context.Request.Params["message"].ToString();
            }
            if (optType == 4)
            {
                message = "人员证书上报";
            }
            if (context.Request.Params["descr"] != null)
            {
                description = context.Request.Params["descr"].ToString();
            }
            //服务参数不够，用User_Log对象传递参数
            ModelService.User_Log log = new ModelService.User_Log();
            //log.IsrtUser = corpUserGuid;
            log.FunctionId = optType.ToString();
            log.FunctionType = message;
            log.Notice = description;
            ////上报
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                string[] arry = eduGuid.Split(',');
                OutputData(client.EmpCertPost(corpUserGuid, JsonConvert.SerializeObject(arry), JsonConvert.SerializeObject(log), areaCode));
            }
        }


        /// <summary>
        /// 人员职称上报审核
        /// </summary>
        /// <param name="empGuid"></param>
        private void EmpPostInfoPost(string empGuid, string areaCode, HttpContext context)
        {
            string corpUserGuid = string.Empty;
            string description = string.Empty;
            string message = string.Empty;
            string appId = ConfigurationManager.AppSettings["AppId"] ?? "";
            int optType = 4;
            if (context.Request.Params["corpGuid"] != null)
            {
                corpUserGuid = context.Request.Params["corpGuid"].ToString();
            }
            if (string.IsNullOrEmpty(empGuid) || string.IsNullOrEmpty(corpUserGuid))
            {
                string result = "{\"Result\":false,\"Message\":\"人员信息为空！\"}";
                OutputData(result);
            }
            if (context.Request.Params["optType"] != null)
            {
                int.TryParse(context.Request.Params["optType"], out optType);
            }

            if (context.Request.Params["message"] != null)
            {
                message = context.Request.Params["message"].ToString();
            }
            if (optType == 4)
            {
                message = "人员职称上报";
            }
            if (context.Request.Params["descr"] != null)
            {
                description = context.Request.Params["descr"].ToString();
            }
            //服务参数不够，用User_Log对象传递参数
            ModelService.User_Log log = new ModelService.User_Log();
            //log.IsrtUser = corpUserGuid;
            log.FunctionId = optType.ToString();
            log.FunctionType = message;
            log.Notice = description;
            ////上报
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                string[] arry = empGuid.Split(',');
                OutputData(client.EmpPostInfoPost(corpUserGuid, JsonConvert.SerializeObject(arry), JsonConvert.SerializeObject(log), areaCode));
            }
        }

        private void GetNonPostExperts(string areaCode, string type, HttpContext context)
        {
            string name = context.Request.QueryString["name"];
            PersonServiceClient client = new PersonServiceClient();
            switch (type)
            {
                case "0":
                case "1":
                    int i = int.Parse(type);
                    List<tb_Emp_ExpertGLD> result = JsonConvert.DeserializeObject<List<tb_Emp_ExpertGLD>>(client.GetNonPostExperts(areaCode, name));
                    List<tb_Emp_ExpertGLD> r = result.Where(rs => rs.ID == i).ToList();
                    OutputData(JsonConvert.SerializeObject(r));
                    break;
                default:
                    OutputData(client.GetNonPostExperts(areaCode, name));
                    break;
            }
        }

        private void GetTreeDeptData(HttpContext context)
        {
            List<NodeEntity> nodes = new List<NodeEntity>();
            List<ModelService.T_Sys_Dict> items = new List<ModelService.T_Sys_Dict>();
            using (BasicService.BasicServiceClient client = new BasicService.BasicServiceClient())
            {
                string parentsid = string.Empty;
                if (context.Request.QueryString["pid"] != null)
                {
                    parentsid = context.Request.QueryString["pid"].Trim();
                }
                items = JsonConvert.DeserializeObject<List<ModelService.T_Sys_Dict>>(client.GetSysDicts("ExpSpec", parentsid, string.Empty));
                foreach (var item in items)
                {
                    NodeEntity node = new NodeEntity();
                    node.isexpand = false;
                    node.pid = item.ParentSID.ToString();
                    node.text = item.Name;
                    node.id = item.SID.ToString();
                    node.code = item.Code;
                    node.children = new List<NodeEntity>();
                    nodes.Add(node);
                }
                UtilitiesTool.OutputData(JsonConvert.SerializeObject(nodes), string.Empty);
            }
        }

        private void LoadSpecDics(HttpContext context)
        {
            string specName = string.Empty;
            if (!string.IsNullOrEmpty(context.Request.QueryString["specName"]))
            {
                specName = context.Request.QueryString["specName"];
                specName = HttpUtility.UrlDecode(specName);
            }
            using (BasicService.BasicServiceClient client = new BasicService.BasicServiceClient())
            {
                var items = JsonConvert.DeserializeObject<List<ModelService.T_Sys_Dict>>(client.GetSysDicts("ExpSpec", string.Empty, string.Empty));
                var rec = items.Where(o => o.Name.Contains(specName)).FirstOrDefault();
                var nodelist = new List<NodeEntity>();
                var roots = new List<NodeEntity>();
                if (rec != null)
                {
                    List<NodeEntity> nodeitems = items.Select(o => new NodeEntity
                    {
                        id = o.SID.ToString(),
                        pid = o.ParentSID.ToString(),
                        code = o.Code,
                        text = o.Name,
                        isexpand = false,
                        ischecked = false,
                        children = new List<NodeEntity>()
                    }).ToList();
                    ////组装树
                    var target = nodeitems.Where(o => o.id == rec.SID.ToString()).FirstOrDefault();
                    target.ischecked = true;
                    while (rec.ParentSID != 0)
                    {
                        var nodes = nodeitems.Where(o => o.pid == rec.ParentSID.ToString()).ToList();
                        var node = nodes.Where(o => o.id == rec.SID.ToString()).First();
                        if (nodelist.Count > 0)
                        {
                            node.children = JsonConvert.DeserializeObject<List<NodeEntity>>(JsonConvert.SerializeObject(nodelist));
                        }
                        else
                        {
                            node.children = new List<NodeEntity>();
                        }
                        node.isexpand = true;
                        nodelist = nodes;
                        rec = items.Where(o => o.SID == rec.ParentSID).FirstOrDefault();
                        if (rec.ParentSID != 0)
                        {
                            var pnodes = nodeitems.Where(o => o.pid == rec.ParentSID.ToString()).ToList();
                            var pnode = pnodes.Where(o => o.id == rec.SID.ToString()).First();
                            pnode.children = nodes;
                            pnode.isexpand = true;
                            nodelist = pnodes;
                            rec = items.Where(o => o.SID == rec.ParentSID).FirstOrDefault();
                            if (rec == null && rec.ParentSID == 0)
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    ////追加根节点
                    roots = nodeitems.Where(o => o.pid == "0").ToList();
                    var root = nodeitems.Where(o => o.id == rec.SID.ToString()).First();
                    root.isexpand = true;
                    root.children = nodelist;
                }
                UtilitiesTool.OutputData(JsonConvert.SerializeObject(roots), string.Empty);
            }
        }

        //private void ExpertSpecCheck(string empGuid, string areaCode, HttpContext context)
        //{
        //    using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
        //    {
        //        var result = client.ExpertMainSpecCheck(empGuid,areaCode);
        //        OutputData(result);
        //    }
        //}

        private void EmpPostPost(string areaCode, HttpContext context)
        {
            ///判断必传图片是否上传
            if (context.Request.Params["funcCode"] != null && context.Request.Params["filename"] != null)
            {
                string funcCodes = context.Request.Params["funcCode"].TrimEnd(',');
                string fileNames = context.Request.Params["filename"].TrimEnd(',');
                string result = CheckRequiredImgs(funcCodes, fileNames);

                if (!string.IsNullOrEmpty(result))
                {
                    OutputData("{\"Result\":false,\"Message\":\"img\",\"ReturnValue\":\"" + result + "\"}");
                    return;
                }
            }

            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                string result = "";
                string empGuid = string.Empty;
                if (context.Request.Params["empGuid"] != null)
                {
                    empGuid = context.Request.Params["empGuid"].ToString();
                    result = client.EmpPostPost(empGuid, areaCode);
                }
                else
                {
                    result = "请先添加人员基本信息！";
                }

                OutputData(result);
            }
        }


        private void GetEmpPostByEmpGuid(string areaCode, HttpContext context)
        {
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                string postStr = string.Empty;
                string empGuid = string.Empty;
                if (context.Request.Params["empGuid"] != null)
                {
                    empGuid = context.Request.Params["empGuid"].ToString();
                    postStr = client.GetEmpPostByEmpGuid(empGuid, areaCode);
                }
                else
                {
                    postStr = "请先添加人员基本信息！";
                }
                OutputData(postStr);
                //OutputData("{\"Result\":true,\"ReturnValue\":\"" + postStr + "\"}");
            }
        }


        #endregion

        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
